package com.woniuxy.controller;


import com.woniuxy.commons.exception.LateException;
import com.woniuxy.commons.utile.Result;
import com.woniuxy.controller.form.RepairEvaluteForm;
import com.woniuxy.dao.model.RepairEvaluate;
import com.woniuxy.service.RepairEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 维修单评价表 前端控制器
 * </p>
 *
 * @author Keep it simple
 * @since 2022-06-28
 */
@RestController
@RequestMapping("/repairEvaluate")
@Api(tags = "订单评价")
public class RepairEvaluateController {

    @Resource
    private RepairEvaluateService repairEvaluateService;


    //增加评价
    @ApiOperation("对维修订单增加评价")
    @PostMapping("/add")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "repairnum",value = "维修编号",dataType = "String",required = true),
            @ApiImplicitParam(name = "evaluateuser",value = "评价人账号",dataType = "String",required = true),
            @ApiImplicitParam(name = "evaluateusername",value = "评价人姓名",dataType = "String",required = true),
            @ApiImplicitParam(name = "attitudestar",value = "维修人员工作态度满意度",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "timelystar",value = "维修响应时间是否及时满意度",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "evaluatecontent",value = "评价类容",dataType = "String",required = true)
    })
    public Result addEvaluate(@Valid @RequestBody RepairEvaluteForm repairEvaluteForm){
        System.out.println(repairEvaluteForm);
        RepairEvaluate isexist = repairEvaluateService.isexist(repairEvaluteForm.getRepairnum());
        if (isexist!=null) throw new LateException(1004,"已评价");
        Integer integer = repairEvaluateService.addoneEvaluate(repairEvaluteForm);
        return Result.instance().setCode(200).setMessage("成功");
    }

}

